/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author ImNotPro
 */
public class Data {

    private String Loc;
    private String Name;
    private byte[] Byte;

    public Data() {
        //
    }

    public Data(JSONObject data) throws JSONException {
        //Read data
        this.Loc = data.getString("path");
        this.Name = data.getString("name");
        String Data = data.getString("content");

        //Create byte
        this.Byte = new byte[Data.length()];
        for (int i = 0; i < this.Byte.length; i++) {
            this.Byte[i] = (byte) Data.charAt(i);
        }
    }

    public JSONObject getJSON() {
        //Create object
        JSONObject JSON = new JSONObject();

        //Read byte to string
        String Data = "";
        for (int i = 0; i < this.Byte.length; i++) {
            Data += (char) this.Byte[i];
        }

        try {
            //Add data
            JSON.put("path", this.Loc);
            JSON.put("name", this.Name);
            JSON.put("content", Data);
        } catch (JSONException ex) {
        }

        //Return json string
        return JSON;
    }

    /**
     * @return the Loc
     */
    public String getLoc() {
        return Loc;
    }

    /**
     * @param Loc the Loc to set
     */
    public void setLoc(String Loc) {
        this.Loc = Loc;
    }

    /**
     * @return the Name
     */
    public String getName() {
        return Name;
    }

    /**
     * @param Name the Name to set
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    /**
     * @return the Byte
     */
    public byte[] getByte() {
        return Byte;
    }

    /**
     * @param Byte the Byte to set
     */
    public void setByte(byte[] Byte) {
        this.Byte = Byte;
    }
}
